github.com/bshelton229/agent@v3.5.4+incompatible/bootstrap/config_test.go (about)

     1  package bootstrap
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/buildkite/agent/env"
     8  )
     9  
    10  func TestEnvVarsAreMappedToConfig(t *testing.T) {
    11  	t.Parallel()
    12  
    13  	config := &Config{
    14  		AutomaticArtifactUploadPaths: "llamas/",
    15  		GitCloneFlags:                "--prune",
    16  		GitCleanFlags:                "-v",
    17  		AgentName:                    "myAgent",
    18  	}
    19  
    20  	environ := env.FromSlice([]string{
    21  		"BUILDKITE_ARTIFACT_PATHS=newpath",
    22  		"BUILDKITE_GIT_CLONE_FLAGS=-f",
    23  		"BUILDKITE_SOMETHING_ELSE=1",
    24  	})
    25  
    26  	changes := config.ReadFromEnvironment(environ)
    27  	expected := map[string]string{
    28  		"BUILDKITE_ARTIFACT_PATHS":  "newpath",
    29  		"BUILDKITE_GIT_CLONE_FLAGS": "-f",
    30  	}
    31  
    32  	if !reflect.DeepEqual(expected, changes) {
    33  		t.Fatalf("%#v wasn't equal to %#v", expected, changes)
    34  	}
    35  
    36  	if expected := "-v"; config.GitCleanFlags != expected {
    37  		t.Fatalf("Expected GitCleanFlags to be %v, got %v",
    38  			expected, config.GitCleanFlags)
    39  	}
    40  }