-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils_test.go
More file actions
63 lines (52 loc) · 1.74 KB
/
utils_test.go
File metadata and controls
63 lines (52 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package controller
import (
"errors"
"os"
"path/filepath"
"testing"
builderconf "github.com/drycc/builder/pkg/conf"
drycc "github.com/drycc/controller-sdk-go"
"github.com/stretchr/testify/assert"
)
func TestNew(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "tmpdir")
if err != nil {
t.Fatalf("error creating temp directory (%s)", err)
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
t.Fatalf("failed to remove service-key from %s (%s)", tmpDir, err)
}
}()
builderconf.ServiceKeyLocation = filepath.Join(tmpDir, "service-key")
data := []byte("testbuilderkey")
if err := os.WriteFile(builderconf.ServiceKeyLocation, data, 0o644); err != nil {
t.Fatalf("error creating %s (%s)", builderconf.ServiceKeyLocation, err)
}
url := "http://127.0.0.1:80"
cli, err := New(url)
assert.Equal(t, err, nil)
assert.Equal(t, cli.ControllerURL.String(), url, "data")
assert.Equal(t, cli.ServiceKey, string(data), "data")
assert.Equal(t, cli.UserAgent, "drycc-builder", "user-agent")
url = "http://127.0.0.1:invalid-port-number"
if _, err = New(url); err == nil {
t.Errorf("expected error with invalid port number, got nil")
}
}
func TestNewWithInvalidBuilderKeyPath(t *testing.T) {
url := "http://127.0.0.1:80"
_, err := New(url)
assert.True(t, err != nil, "no error received when there should have been")
}
func TestCheckAPICompat(t *testing.T) {
client := &drycc.Client{ControllerAPIVersion: drycc.APIVersion}
err := drycc.ErrAPIMismatch
if apiErr := CheckAPICompat(client, err); apiErr != nil {
t.Errorf("api errors are non-fatal and should return nil, got '%v'", apiErr)
}
err = errors.New("random error")
if apiErr := CheckAPICompat(client, err); apiErr == nil {
t.Error("expected error to be returned, got nil")
}
}