MCPcopy Create free account
hub / github.com/coder/envbuilder / TestBuildFromDockerfileAndConfig

Function TestBuildFromDockerfileAndConfig

integration/integration_test.go:665–801  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

663}
664
665func TestBuildFromDockerfileAndConfig(t *testing.T) {
666 t.Parallel()
667
668 type configFile struct {
669 name string
670 data string
671 }
672 type testCase struct {
673 name string
674 env []string
675 configFile configFile
676 configBase64 string
677 validate func(t *testing.T, tc testCase, ctrID, logs string)
678 }
679
680 validateDockerConfig := func(t *testing.T, tc testCase, ctrID, logs string) {
681 t.Helper()
682
683 // Ensure that the config matches the expected value, base64 is
684 // always prioritized over a file.
685 got := execContainer(t, ctrID, "cat /docker_config_json")
686 got = strings.TrimSpace(got)
687 want := tc.configBase64
688 if want == "" {
689 want = tc.configFile.data
690 }
691 if want != "" {
692 require.Contains(t, logs, "Set DOCKER_CONFIG to /.envbuilder/.docker")
693 require.Equal(t, want, got)
694 }
695
696 // Ensure that a warning message is printed if config secrets
697 // will remain in the container after build.
698 warningMessage := "this file will remain after the build"
699 if tc.configFile.name != "" {
700 require.Contains(t, logs, warningMessage)
701 } else {
702 require.NotContains(t, logs, warningMessage)
703 }
704 }
705
706 configJSONContainerPath := workingdir.Default.Join(".docker", "config.json")
707 defaultConfigJSON := `{"experimental": "enabled"}`
708
709 tests := []testCase{
710 {
711 name: "Plain",
712 validate: func(t *testing.T, tc testCase, ctrID, logs string) {
713 output := execContainer(t, ctrID, "echo hello")
714 require.Equal(t, "hello", strings.TrimSpace(output))
715 },
716 },
717 {
718 name: "ConfigBase64",
719 configBase64: defaultConfigJSON,
720 validate: validateDockerConfig,
721 },
722 {

Callers

nothing calls this directly

Calls 5

CreateGitServerFunction · 0.92
execContainerFunction · 0.85
envbuilderEnvFunction · 0.85
runEnvbuilderFunction · 0.85
JoinMethod · 0.80

Tested by

no test coverage detected