Skip to content

Commit

Permalink
fix: Fix automated publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed May 12, 2024
1 parent 19b2f16 commit c7830c3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
30 changes: 3 additions & 27 deletions internal/auth/token_test.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
package auth

import (
"fmt"
"os"
"runtime"
"testing"

"github.com/prantlf/ovai/internal/test"
)

type testPart struct {
Test string `json:"test"`
}

var wd = getWd()
var wdLen = len(wd) + 1

func getWd() string {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
return wd
}

func location() string {
if _, file, line, ok := runtime.Caller(2); ok {
return fmt.Sprintf("%s:%d: ", file[wdLen:], line)
}
return ""
}

func equal(t *testing.T, expected any, actual any) {
if expected != actual {
t.Errorf("%snot equal\nexpected: %v\nactual: %v", location(), expected, actual)
}
}
func TestEncodePart(t *testing.T) {
out, err := encodePart(&testPart{
Test: "test",
})
if err != nil {
t.Fatal(err)
}
equal(t, "eyJ0ZXN0IjoidGVzdCJ9", out)
test.Equal(t, "eyJ0ZXN0IjoidGVzdCJ9", out)
}

func TestCreateToken(t *testing.T) {
Expand Down
32 changes: 32 additions & 0 deletions internal/test/assert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package test

import (
"fmt"
"os"
"runtime"
"testing"
)

var wd = getWd()
var wdLen = len(wd) + 1

func getWd() string {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
return wd
}

func location() string {
if _, file, line, ok := runtime.Caller(2); ok {
return fmt.Sprintf("%s:%d: ", file[wdLen:], line)
}
return ""
}

func Equal(t *testing.T, expected any, actual any) {
if expected != actual {
t.Errorf("%snot equal\nexpected: %v\nactual: %v", location(), expected, actual)
}
}

0 comments on commit c7830c3

Please sign in to comment.