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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
package runner
// import (
// "context"
// "os"
// "testing"
// "time"
// "github.com/stretchr/testify/require"
// "google.golang.org/grpc/codes"
// "google.golang.org/grpc/status"
// "github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
// "github.com/hashicorp/vagrant/internal/server/singleprocess"
// )
// func TestRunnerStart(t *testing.T) {
// require := require.New(t)
// ctx := context.Background()
// client := singleprocess.TestServer(t)
// rubyRunTime, err := TestRunnerVagrantRubyRuntime(t)
// defer rubyRunTime.Close()
// // Initialize our runner
// runner, err := New(
// WithClient(client),
// WithVagrantRubyRuntime(rubyRunTime),
// )
// require.NoError(err)
// defer runner.Close()
// // The runner should not be registered
// _, err = client.GetRunner(ctx, &vagrant_server.GetRunnerRequest{RunnerId: runner.Id()})
// require.Error(err)
// require.Equal(codes.NotFound, status.Code(err))
// // Start it
// require.NoError(runner.Start())
// // The runner should be registered
// resp, err := client.GetRunner(ctx, &vagrant_server.GetRunnerRequest{RunnerId: runner.Id()})
// require.NoError(err)
// require.Equal(runner.Id(), resp.Id)
// // Close
// require.NoError(runner.Close())
// time.Sleep(100 * time.Millisecond)
// // The runner should not be registered
// _, err = client.GetRunner(ctx, &vagrant_server.GetRunnerRequest{RunnerId: runner.Id()})
// require.Error(err)
// require.Equal(codes.NotFound, status.Code(err))
// }
// func TestRunnerStart_config(t *testing.T) {
// t.Run("set and unset", func(t *testing.T) {
// require := require.New(t)
// ctx := context.Background()
// client := singleprocess.TestServer(t)
// cfgVar := &vagrant_server.ConfigVar{
// Scope: &vagrant_server.ConfigVar_Runner{
// Runner: &vagrant_server.Ref_Runner{
// Target: &vagrant_server.Ref_Runner_Any{
// Any: &vagrant_server.Ref_RunnerAny{},
// },
// },
// },
// Name: "I_AM_A_TEST_VALUE",
// Value: "1234567890",
// }
// // Initialize our runner
// runner := TestRunner(t, WithClient(client))
// defer runner.Close()
// require.NoError(runner.Start())
// // Verify it is not set
// require.Empty(os.Getenv(cfgVar.Name))
// // Set some config
// _, err := client.SetConfig(ctx, &vagrant_server.ConfigSetRequest{Variables: []*vagrant_server.ConfigVar{cfgVar}})
// require.NoError(err)
// // Should be set
// require.Eventually(func() bool {
// return os.Getenv(cfgVar.Name) == cfgVar.Value
// }, 1000*time.Millisecond, 50*time.Millisecond)
// // Unset
// cfgVar.Value = ""
// _, err = client.SetConfig(ctx, &vagrant_server.ConfigSetRequest{Variables: []*vagrant_server.ConfigVar{cfgVar}})
// require.NoError(err)
// // Should be unset
// require.Eventually(func() bool {
// return os.Getenv(cfgVar.Name) == ""
// }, 1000*time.Millisecond, 50*time.Millisecond)
// })
// t.Run("unset with original env", func(t *testing.T) {
// require := require.New(t)
// ctx := context.Background()
// client := singleprocess.TestServer(t)
// cfgVar := &vagrant_server.ConfigVar{
// Scope: &vagrant_server.ConfigVar_Runner{
// Runner: &vagrant_server.Ref_Runner{
// Target: &vagrant_server.Ref_Runner_Any{
// Any: &vagrant_server.Ref_RunnerAny{},
// },
// },
// },
// Name: "I_AM_A_TEST_VALUE",
// Value: "1234567890",
// }
// // Set a value
// require.NoError(os.Setenv(cfgVar.Name, "ORIGINAL"))
// defer os.Unsetenv(cfgVar.Name)
// // Initialize our runner
// runner := TestRunner(t, WithClient(client))
// defer runner.Close()
// require.NoError(runner.Start())
// // Set some config
// _, err := client.SetConfig(ctx, &vagrant_server.ConfigSetRequest{Variables: []*vagrant_server.ConfigVar{cfgVar}})
// require.NoError(err)
// // Should be set
// require.Eventually(func() bool {
// return os.Getenv(cfgVar.Name) == cfgVar.Value
// }, 1000*time.Millisecond, 50*time.Millisecond)
// // Unset
// cfgVar.Value = ""
// _, err = client.SetConfig(ctx, &vagrant_server.ConfigSetRequest{Variables: []*vagrant_server.ConfigVar{cfgVar}})
// require.NoError(err)
// // Should be unset back to original value
// require.Eventually(func() bool {
// return os.Getenv(cfgVar.Name) == "ORIGINAL"
// }, 1000*time.Millisecond, 50*time.Millisecond)
// })
// }
|