Skip to content

Commit

Permalink
Backwards compat for gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout committed Oct 21, 2024
1 parent 4ff0375 commit 171fd75
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/runnerv2service/service_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func (r *runnerService) CreateSession(ctx context.Context, req *runnerv2.CreateS
if cfg.GetEnvStoreType() == runnerv2.SessionEnvStoreType_SESSION_ENV_STORE_TYPE_OWL {
owl = true
}
} else {
// todo(sebastian): Support legacy behavior for pre-proto change clients. Remove this after a while.
seedEnv = os.Environ()
}

sess, err := session.New(session.WithOwl(owl), session.WithProject(proj), session.WithSeedEnv(seedEnv))
Expand Down
42 changes: 40 additions & 2 deletions internal/runnerv2service/service_sessions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ func TestRunnerServiceSessions(t *testing.T) {
t.Cleanup(stop)
_, client := testCreateRunnerServiceClient(t, lis)

EnvStoreSeedingNone := runnerv2.CreateSessionRequest_Config_SESSION_ENV_STORE_SEEDING_UNSPECIFIED.Enum()

t.Run("WithEnv", func(t *testing.T) {
createResp, err := client.CreateSession(context.Background(), &runnerv2.CreateSessionRequest{})
require.NoError(t, err)
require.NotNil(t, createResp.Session)

createResp, err = client.CreateSession(context.Background(), &runnerv2.CreateSessionRequest{Env: []string{"TEST1=value1"}})
createResp, err = client.CreateSession(context.Background(),
&runnerv2.CreateSessionRequest{
Env: []string{"TEST1=value1"},
Config: &runnerv2.CreateSessionRequest_Config{EnvStoreSeeding: EnvStoreSeedingNone},
},
)
require.NoError(t, err)
require.EqualValues(t, []string{"TEST1=value1"}, createResp.Session.Env)

Expand Down Expand Up @@ -55,13 +62,44 @@ func TestRunnerServiceSessions(t *testing.T) {
projectPath := testData.GitProjectPath()
createResp, err := client.CreateSession(
context.Background(),
&runnerv2.CreateSessionRequest{Project: &runnerv2.Project{Root: projectPath, EnvLoadOrder: []string{".env"}}},
&runnerv2.CreateSessionRequest{
Config: &runnerv2.CreateSessionRequest_Config{EnvStoreSeeding: EnvStoreSeedingNone},
Project: &runnerv2.Project{Root: projectPath, EnvLoadOrder: []string{".env"}},
},
)
require.NoError(t, err)
require.NotNil(t, createResp.Session)
require.EqualValues(t, []string{"PROJECT_ENV_FROM_DOTFILE=1"}, createResp.Session.Env)
})

t.Run("WithEnvStoreSeedingSystem", func(t *testing.T) {
EnvStoreSeedingSystem := runnerv2.CreateSessionRequest_Config_SESSION_ENV_STORE_SEEDING_SYSTEM.Enum()
createResp, err := client.CreateSession(
context.Background(),
&runnerv2.CreateSessionRequest{
Env: []string{"TEST1=value1"},
Config: &runnerv2.CreateSessionRequest_Config{EnvStoreSeeding: EnvStoreSeedingSystem},
},
)
require.NoError(t, err)
require.NotNil(t, createResp.Session)
require.Greater(t, len(createResp.Session.Env), 1)
require.Contains(t, createResp.Session.Env, "TEST1=value1")
})

t.Run("WithEnvStoreSeedingLegacy", func(t *testing.T) {
createResp, err := client.CreateSession(
context.Background(),
&runnerv2.CreateSessionRequest{
Env: []string{"TEST1=value1"},
},
)
require.NoError(t, err)
require.NotNil(t, createResp.Session)
require.Greater(t, len(createResp.Session.Env), 1)
require.Contains(t, createResp.Session.Env, "TEST1=value1")
})

t.Run("WithProjectInvalid", func(t *testing.T) {
_, err := client.CreateSession(
context.Background(),
Expand Down

0 comments on commit 171fd75

Please sign in to comment.