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
|
// Copyright (c) 2018-2020, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package remotebuilder
import (
"os"
"runtime"
"testing"
"github.com/sylabs/singularity/v4/internal/pkg/test"
"github.com/sylabs/singularity/v4/pkg/build/types"
useragent "github.com/sylabs/singularity/v4/pkg/util/user-agent"
)
func TestMain(m *testing.M) {
useragent.InitValue("singularity", "3.0.0-alpha.1-303-gaed8d30-dirty")
os.Exit(m.Run())
}
func TestBuild(t *testing.T) {
test.DropPrivilege(t)
defer test.ResetPrivilege(t)
tests := []struct {
description string
expectSuccess bool
builderAddr string
}{
{"BadBuilderURI", false, "ftp:?abc//foo.bar:abc"},
{"BadBuilderScheme", false, "ftp://build.sylabs.io"},
{"SuccessBuilderAddr", true, "http://build.sylabs.io"},
{"SuccessBuilderAddrSecure", true, "https://build.sylabs.io"},
}
// Loop over test cases
for _, tt := range tests {
t.Run(tt.description, test.WithoutPrivilege(func(t *testing.T) {
_, err := New("", "", types.Definition{}, false, false, tt.builderAddr, "", runtime.GOARCH, "")
if tt.expectSuccess {
// Ensure the handler returned no error, and the response is as expected
if err != nil {
t.Fatalf("unexpected failure: %v", err)
}
} else {
// Ensure the handler returned an error
if err == nil {
t.Fatalf("unexpected success")
}
}
}))
}
}
|