How to use Twelve method of source Package

Best Mock code snippet using source.Twelve

integration_test.go

Source:integration_test.go Github

copy

Full Screen

...108// SQL SERVER -> S3109func testCpSnapSqlServerS3(name string, t *testing.T) {110 t.Log(name)111 _ = os.Setenv("AWS_PROFILE", "halfpipe")112 _ = os.Unsetenv(envVarTwelveFactorMode)113 setupTwelveFactorMode()114 // Run the cp snap test.115 cpSnapCfg.Connections = getConnectionHandler()116 cpSnapCfg.SourceString = actions.ConnectionObject{ConnectionObject: "sqlserver.test_cp_delta"}117 cpSnapCfg.TargetString = actions.ConnectionObject{ConnectionObject: "s3.test_cp_snap"}118 cpSnapCfg.LogLevel = "error"119 if err := runCpSnap(); err != nil {120 t.Fatal("Failed to run test cp snap from SqlServer to S3:", err)121 }122}123func testCpDeltaSqlServerS3(name string, t *testing.T) {124 t.Log(name)125 cpDeltaSqlServerS3Date(t)126 cpDeltaSqlServerS3Number(t)127}128// SQL SERVER -> SNOWFLAKE:129func testCpSnapSqlServerSnowflake(name string, t *testing.T) {130 t.Log(name)131 _ = os.Setenv("AWS_PROFILE", "halfpipe")132 _ = os.Unsetenv(envVarTwelveFactorMode)133 setupTwelveFactorMode()134 dropAndCreateCpDeltaTable(t)135 // Run the cp snap test.136 cpSnapCfg.Connections = getConnectionHandler()137 cpSnapCfg.SourceString = actions.ConnectionObject{ConnectionObject: "sqlserver.test_cp_delta"}138 cpSnapCfg.TargetString = actions.ConnectionObject{ConnectionObject: "snowflake.test_cp_delta"}139 cpSnapCfg.LogLevel = "error"140 if err := runCpSnap(); err != nil {141 t.Fatal("Failed to run test cp snap from SqlServer to Snowflake:", err)142 }143 // Drop the table again.144 if err := actions.RunQuery(&queryCfg); err != nil {145 t.Fatal("Failed to drop table for cp meta cleanup:", err)146 }147 dropCpDeltaTable(t)148}149func testCpDeltaSqlServerSnowflake(name string, t *testing.T) {150 t.Log(name)151 testCpDeltaSqlServerSnowflakeDate(t)152 testCpDeltaSqlServerSnowflakeNumber(t)153}154func testCpDeltaSqlServerSnowflakeDate(t *testing.T) {155 _ = os.Setenv("AWS_PROFILE", "halfpipe")156 _ = os.Unsetenv(envVarTwelveFactorMode)157 setupTwelveFactorMode()158 dropAndCreateCpDeltaTable(t)159 // Run the cp delta test.160 cpDeltaCfg.Connections = getConnectionHandler()161 cpDeltaCfg.SourceString = actions.ConnectionObject{ConnectionObject: "sqlserver.test_cp_delta"}162 cpDeltaCfg.TargetString = actions.ConnectionObject{ConnectionObject: "snowflake.test_cp_delta"}163 cpDeltaCfg.LogLevel = "error"164 cpDeltaCfg.SQLPrimaryKeyFieldsCsv = "PRD_LVL_CHILD"165 cpDeltaCfg.SQLBatchDriverField = "LAST_MODIFIED"166 cpDeltaCfg.SQLBatchSize = "30"167 if err := runCpDelta(); err != nil {168 t.Fatal("Failed test cp delta from SqlServer to Snowflake using date driver:", err)169 }170 dropCpDeltaTable(t)171}172func testCpDeltaSqlServerSnowflakeNumber(t *testing.T) {173 _ = os.Setenv("AWS_PROFILE", "halfpipe")174 _ = os.Unsetenv(envVarTwelveFactorMode)175 setupTwelveFactorMode()176 dropAndCreateCpDeltaTable(t)177 // Run the cp delta test.178 cpDeltaCfg.Connections = getConnectionHandler()179 cpDeltaCfg.SourceString = actions.ConnectionObject{ConnectionObject: "sqlserver.test_cp_delta"}180 cpDeltaCfg.TargetString = actions.ConnectionObject{ConnectionObject: "snowflake.test_cp_delta"}181 cpDeltaCfg.LogLevel = "error"182 cpDeltaCfg.SQLPrimaryKeyFieldsCsv = "PRD_LVL_CHILD"183 cpDeltaCfg.SQLBatchDriverField = "PRD_LVL_CHILD"184 cpDeltaCfg.SQLBatchSize = "125000"185 if err := runCpDelta(); err != nil {186 t.Fatal("Failed test cp delta from SqlServer to Snowflake using date driver:", err)187 }188 dropCpDeltaTable(t)189}190// S3 -> SNOWFLAKE:191func testCpSnapS3Snowflake(name string, t *testing.T) {192 t.Log(name)193 _ = os.Setenv("AWS_PROFILE", "halfpipe")194 _ = os.Unsetenv(envVarTwelveFactorMode)195 setupTwelveFactorMode()196 // Setup data files in S3.197 cpDeltaSqlServerS3Date(t)198 // Setup target table.199 dropAndCreateCpDeltaTable(t)200 // Tests:201 cpSnapCfg.Connections = getConnectionHandler()202 cpSnapCfg.SourceString = actions.ConnectionObject{ConnectionObject: "s3.test_cp_delta"}203 cpSnapCfg.TargetString = actions.ConnectionObject{ConnectionObject: "snowflake.test_cp_delta"}204 cpSnapCfg.LogLevel = "error"205 if err := runCpSnap(); err != nil {206 t.Fatal("Failed to run test cp snap from S3 to Snowflake:", err)207 }208 dropCpDeltaTable(t)209}210func testCpDeltaS3Snowflake(name string, t *testing.T) {211 t.Log(name)212 testCpDeltaS3SnowflakeDate(t)213 testCpDeltaS3SnowflakeNumber(t)214}215func testCpDeltaS3SnowflakeDate(t *testing.T) {216 _ = os.Setenv("AWS_PROFILE", "halfpipe")217 _ = os.Unsetenv(envVarTwelveFactorMode)218 setupTwelveFactorMode()219 // Setup data files in S3.220 cpDeltaSqlServerS3Date(t)221 // Setup target table.222 dropAndCreateCpDeltaTable(t)223 // Tests:224 cpDeltaCfg.Connections = getConnectionHandler()225 cpDeltaCfg.SourceString = actions.ConnectionObject{ConnectionObject: "s3.test_cp_delta"}226 cpDeltaCfg.TargetString = actions.ConnectionObject{ConnectionObject: "snowflake.test_cp_delta"}227 cpDeltaCfg.LogLevel = "error"228 cpDeltaCfg.SQLPrimaryKeyFieldsCsv = "PRD_LVL_CHILD"229 cpDeltaCfg.SQLBatchDriverField = "LAST_MODIFIED"230 cpDeltaCfg.SQLBatchSize = "30"231 if err := runCpDelta(); err != nil {232 t.Fatal("Failed test cp delta from S3 to Snowflake using date driver:", err)233 }234 dropCpDeltaTable(t)235}236func testCpDeltaS3SnowflakeNumber(t *testing.T) {237 _ = os.Setenv("AWS_PROFILE", "halfpipe")238 _ = os.Unsetenv(envVarTwelveFactorMode)239 setupTwelveFactorMode()240 // Setup data files in S3.241 cpDeltaSqlServerS3Number(t)242 // Setup target table.243 dropAndCreateCpDeltaTable(t)244 // Tests:245 cpDeltaCfg.Connections = getConnectionHandler()246 cpDeltaCfg.SourceString = actions.ConnectionObject{ConnectionObject: "s3.test_cp_delta"}247 cpDeltaCfg.TargetString = actions.ConnectionObject{ConnectionObject: "snowflake.test_cp_delta"}248 cpDeltaCfg.LogLevel = "error"249 cpDeltaCfg.SQLPrimaryKeyFieldsCsv = "PRD_LVL_CHILD"250 cpDeltaCfg.SQLBatchDriverField = "PRD_LVL_CHILD"251 cpDeltaCfg.SQLBatchSize = "125000" // the range of numbers across 999 sample records is 123893.252 if err := runCpDelta(); err != nil {253 t.Fatal("Failed test cp delta from S3 to Snowflake using number driver:", err)254 }255 dropCpDeltaTable(t)256}257// ----------------------------------------------------------------------------258// QUERY259// ----------------------------------------------------------------------------260func testQueryOracle(name string, t *testing.T) {261 t.Log(name)262 // Expect connection 'oracle' to exist and execute a benign query against it.263 _ = os.Unsetenv(envVarTwelveFactorMode)264 setupTwelveFactorMode() // unset 12factor mode265 c := "oracle"266 q := actions.QueryConfig{267 Connections: getConnectionLoader(),268 SourceString: actions.ConnectionObject{ConnectionObject: c},269 Query: "select 1 from dual",270 PrintHeader: false,271 DryRun: false,272 LogLevel: "error",273 StackDumpOnPanic: false,274 }275 err := actions.RunQuery(&q)276 if err != nil {277 t.Fatalf("Test failed: could not execute query against connection '%v': %v", c, err)278 }279}280// ----------------------------------------------------------------------------281// HELPERS:282// ----------------------------------------------------------------------------283func dropCpDeltaTable(t *testing.T) {284 // Drop target Snowflake table.285 queryCfg.Connections = getConnectionLoader()286 queryCfg.SourceString = actions.ConnectionObject{ConnectionObject: "snowflake"}287 queryCfg.Query = "drop table test_cp_delta"288 if err := actions.RunQuery(&queryCfg); err != nil {289 t.Log("Ignorable failure to drop table:", err)290 }291}292func dropAndCreateCpDeltaTable(t *testing.T) {293 // Recreate target Snowflake table.294 dropCpDeltaTable(t)295 cpMetaCfg.Connections = getConnectionHandler()296 cpMetaCfg.SourceString = actions.ConnectionObject{ConnectionObject: "sqlserver.test_cp_delta"}297 cpMetaCfg.TargetString = actions.ConnectionObject{ConnectionObject: "snowflake.test_cp_delta"}298 cpMetaCfg.ExecuteDDL = true299 if err := runCpMeta(); err != nil {300 t.Fatal("Failed to create table for cp meta test:", err)301 }302}303func cpDeltaSqlServerS3Date(t *testing.T) {304 _ = os.Setenv("AWS_PROFILE", "halfpipe")305 _ = os.Unsetenv(envVarTwelveFactorMode)306 setupTwelveFactorMode()307 // Run the cp delta test.308 cpDeltaCfg.Connections = getConnectionHandler()309 cpDeltaCfg.SourceString = actions.ConnectionObject{ConnectionObject: "sqlserver.test_cp_delta"}310 cpDeltaCfg.TargetString = actions.ConnectionObject{ConnectionObject: "s3.test_cp_delta"}311 cpDeltaCfg.LogLevel = "error"312 cpDeltaCfg.SQLBatchDriverField = "LAST_MODIFIED"313 cpDeltaCfg.SQLBatchSize = "30"314 if err := runCpDelta(); err != nil {315 t.Fatal("Failed test cp delta from SqlServer to S3 using date driver:", err)316 }317}318func cpDeltaSqlServerS3Number(t *testing.T) {319 _ = os.Setenv("AWS_PROFILE", "halfpipe")320 _ = os.Unsetenv(envVarTwelveFactorMode)321 setupTwelveFactorMode()322 cpDeltaCfg.Connections = getConnectionHandler()323 cpDeltaCfg.SourceString = actions.ConnectionObject{ConnectionObject: "sqlserver.test_cp_delta"}324 cpDeltaCfg.TargetString = actions.ConnectionObject{ConnectionObject: "s3.test_cp_delta"}325 cpDeltaCfg.LogLevel = "error"326 cpDeltaCfg.SQLBatchDriverField = "PRD_LVL_CHILD"327 cpDeltaCfg.SQLBatchSize = "125000" // the range of numbers across 999 sample records is 123893.328 if err := runCpDelta(); err != nil {329 t.Fatal("Failed test cp delta from SqlServer to S3 using number driver:", err)330 }331}332// Oracle-Oracle333func TestCpSnapOracleOracle(t *testing.T) {334 testCpSnapOracleOracle("testCpSnapOracleOracle", t)335}336func testCpSnapOracleOracle(name string, t *testing.T) {337 t.Log(name)338 _ = os.Setenv("AWS_PROFILE", "halfpipe")339 _ = os.Unsetenv(envVarTwelveFactorMode)340 setupTwelveFactorMode()341 cpSnapCfg.Connections = getConnectionHandler()342 cpSnapCfg.SourceString = actions.ConnectionObject{ConnectionObject: "oracle.demo_source"}343 cpSnapCfg.TargetString = actions.ConnectionObject{ConnectionObject: "oracle.demo_target"}344 cpSnapCfg.LogLevel = "error"345 if err := runCpSnap(); err != nil {346 t.Fatal("Failed test cp snap from oracle to oracle:", err)347 }348}...

Full Screen

Full Screen

12factor.go

Source:12factor.go Github

copy

Full Screen

...17// This ensures the value of twelveFactorMode is set such that other init() functions that configure18// Cobra can do the job of processing all environment variables that would contain equivalent of the CLI flag19// structures used by Halfpipe's actions.20func init() {21 setupTwelveFactorMode()22}23// setupTwelveFactorMode will enable or disable 12 factor mode based on environment variable.24func setupTwelveFactorMode() {25 mode := os.Getenv(envVarTwelveFactorMode)26 if mode != "" { // if variable for 12factor mode is set and we should read env vars to determine actions...27 twelveFactorMode = true28 if strings.ToLower(mode) == "lambda" {29 lambdaMode = true30 }31 } else { // else 12factor mode should be off...32 twelveFactorMode = false // explicitly turn off this mode since tests may have turned it on while others require it off.33 }34}35const (36 envVarTwelveFactorMode = c.EnvVarPrefix + "_" + "12FACTOR_MODE"37 envVarCommand = c.EnvVarPrefix + "_" + "COMMAND"38 envVarSubcommand = c.EnvVarPrefix + "_" + "SUBCOMMAND"39 envVarSourceObject = c.EnvVarPrefix + "_" + "SOURCE_OBJECT" // <connection-name>.[<schema>.]<table>40 envVarTargetObject = c.EnvVarPrefix + "_" + "TARGET_OBJECT" // <connection-name>.[<schema>.]<table>41 envVarSourceType = c.EnvVarPrefix + "_" + "SOURCE_TYPE" // oracle|snowflake|etc42 envVarSourceS3Region = c.EnvVarPrefix + "_" + "SOURCE_S3_REGION"43 envVarTargetType = c.EnvVarPrefix + "_" + "TARGET_TYPE" // oracle|snowflake|etc44 envVarTargetS3Region = c.EnvVarPrefix + "_" + "TARGET_S3_REGION"45 envVarAuthKey = c.EnvVarPrefix + "_" + "AUTH_KEY"46 envVarLogLevel = c.EnvVarPrefix + "_" + "LOG_LEVEL"47 envVarStackDump = c.EnvVarPrefix + "_" + "STACK_DUMP"48 defaultConnectionNameSource = "SOURCE"49 defaultConnectionNameTarget = "TARGET"50)51var (52 twelveFactorMode bool // true if os env var envVarTwelveFactorMode is set53 lambdaMode bool // true if os env var envVarLambdaMode is set54 twelveFactorVars = map[string]string{55 envVarCommand: "",56 envVarSubcommand: "",57 // Source58 envVarSourceType: "",59 helper.GetDsnEnvVarName(defaultConnectionNameSource): "",60 envVarSourceObject: "",61 envVarSourceS3Region: "",62 // Target63 envVarTargetType: "",64 helper.GetDsnEnvVarName(defaultConnectionNameTarget): "",65 envVarTargetObject: "",66 envVarTargetS3Region: "",67 // Misc68 envVarAuthKey: "",69 c.EnvVarAuthzAmiMode: "",70 envVarLogLevel: "",71 envVarStackDump: "",72 }73 twelveFactorVarsSensitive = map[string]string{ // used to flag some of the above variables as being sensitive.74 envVarAuthKey: "",75 }76)77type twelveFactorAction struct {78 setupFunc func(src string, tgt string)79 runnerFunc func() error80}81var twelveFactorActions = map[string]twelveFactorAction{82 "cp-snap": {83 setupFunc: func(src string, tgt string) {84 cpSnapCfg.SrcAndTgtConnections.SourceString.ConnectionObject = src85 cpSnapCfg.SrcAndTgtConnections.TargetString.ConnectionObject = tgt86 },87 runnerFunc: runCpSnap,88 },89 "cp-delta": {90 setupFunc: func(src string, tgt string) {91 cpDeltaCfg.SrcAndTgtConnections.SourceString.ConnectionObject = src92 cpDeltaCfg.SrcAndTgtConnections.TargetString.ConnectionObject = tgt93 },94 runnerFunc: runCpDelta,95 },96 "sync-batch": {97 setupFunc: func(src string, tgt string) {98 syncBatchCfg.SrcAndTgtConnections.SourceString.ConnectionObject = src99 syncBatchCfg.SrcAndTgtConnections.TargetString.ConnectionObject = tgt100 },101 runnerFunc: runSyncBatch,102 },103 "sync-events": {104 setupFunc: func(src string, tgt string) {105 syncEventsCfg.SrcAndTgtConnections.SourceString.ConnectionObject = src106 syncEventsCfg.SrcAndTgtConnections.TargetString.ConnectionObject = tgt107 },108 runnerFunc: runSyncEvents,109 },110}111func getConnectionHandler() actions.ConnectionHandler {112 if twelveFactorMode {113 return &TwelveFactorConnections{}114 } else {115 return config.Connections116 }117}118func getConnectionLoader() actions.ConnectionLoader {119 if twelveFactorMode {120 return &TwelveFactorConnections{}121 } else {122 return config.Connections123 }124}125func getConnectionGetterSetter() actions.ConnectionGetterSetter {126 if twelveFactorMode {127 fmt.Printf("Error: connections cannot be configured when %v is set (supply them using %v and %v instead)",128 envVarTwelveFactorMode,129 helper.GetDsnEnvVarName("<source-connection-name>"),130 helper.GetDsnEnvVarName("<target-connection-name>"))131 os.Exit(1)132 }133 return config.Connections134}135func execute12FactorMode(acts map[string]twelveFactorAction) (err error) {136 logLevel := helper.ReadValueFromEnvWithDefault(envVarLogLevel, "warn") // fetch logLevel from env as this is not a persistent flag, given that we wanted different logging defaults per cobra action.137 log := logger.NewLogger("halfpipe", logLevel, stackDumpOnPanic)138 log.Info("Halfpipe is running in 12 Factor mode...")139 // Save values for the required variables.140 // TODO: add validation of supplied env variables - perhaps using a map[string]MyStructWithValidationData.141 for k := range twelveFactorVars { // for each env variable that we need...142 // Save it and log it.143 twelveFactorVars[k] = os.Getenv(k)144 _, sensitive := twelveFactorVarsSensitive[k]145 if !sensitive { // if the env variable does not contain sensitive values...146 // Log the value.147 log.Debug(k, "=", twelveFactorVars[k])148 } else { // else output obfuscated value...149 log.Debug(k, "=", "<obfuscated>")150 }151 }152 // Use command and subcommand to fetch the appropriate action.153 action := fmt.Sprintf("%v-%v", twelveFactorVars[envVarCommand], twelveFactorVars[envVarSubcommand])154 a, ok := acts[action]155 if !ok {156 err = fmt.Errorf("invalid combination of command (%v) and subcommand (%v)", twelveFactorVars[envVarCommand], twelveFactorVars[envVarSubcommand])157 log.Error(err.Error())158 return159 }160 // Setup the connection source and target strings to include the object, as Cobra would have with CLI args.161 a.setupFunc(162 fmt.Sprintf("%v.%v", defaultConnectionNameSource, twelveFactorVars[envVarSourceObject]), // e.g. SOURCE.ORACLE.test_a163 fmt.Sprintf("%v.%v", defaultConnectionNameTarget, twelveFactorVars[envVarTargetObject]), // e.g. TARGET.ORACLE.test_b164 )165 // Run the action.166 err = a.runnerFunc()167 if err != nil {168 log.Error("Error: ", err)169 }170 return err171}172type TwelveFactorConnections struct{} // implements interfaces in module, actions.173// GetConnectionType is for use when running in twelveFactorMode.174// It returns the value of envVarSourceType or envVarTargetType based on the supplied connectionName,175// where connectionName is expected to bee either defaultConnectionNameSource or defaultConnectionNameTarget.176// It reads the global map twelveFactorVars[] which should have been setup using environment variables.177func (t *TwelveFactorConnections) GetConnectionType(connectionName string) (connectionType string, err error) {178 var ok bool179 if connectionName == defaultConnectionNameSource {180 connectionType, ok = twelveFactorVars[envVarSourceType]181 if !ok {182 err = fmt.Errorf("missing value for %v", envVarSourceType)183 }184 } else if connectionName == defaultConnectionNameTarget {185 connectionType, ok = twelveFactorVars[envVarTargetType]186 if !ok {187 err = fmt.Errorf("missing value for %v", envVarTargetType)188 }189 } else {190 err = fmt.Errorf("unexpected connectionName %v while running in twelveFactorMode", connectionName)191 }192 return193}194// GetConnectionDetails expects outConnectionDetails to be a pointer to a connection-specific struct,195// which it fills with connection details fetched from env variables by using the connectionName to do the lookup,196// where the connectionName is either source or target.197// The connection type is picked up from the environment using variable whose name matches constant envVarSourceType198// and envVarTargetType respectively.199// If the type of outConnectionDetails does not match the type found inside the connection then an200// error is produced, otherwise the config keys and values are put into outConnectionDetails.201// TODO: add tests for GetConnectionDetails202func (t *TwelveFactorConnections) GetConnectionDetails(connectionName string) (*shared.ConnectionDetails, error) {203 var kDsn, vDsn, vType string204 var err error205 var connectionDetails shared.ConnectionDetails206 connectionDetails.Data = make(map[string]string)207 connectionDetails.LogicalName = connectionName208 // Fetch connection info from the environment based on the connection name.209 kDsn = helper.GetDsnEnvVarName(connectionName)210 if err = helper.ReadValueFromEnv(kDsn, &vDsn); err != nil { // if we cannot find the connection type in the environment...211 return nil, fmt.Errorf("unable to find value for %v in the environment: %w", vDsn, err)212 }213 // Fetch connection type from the environment based on the connection name.214 vType, err = t.GetConnectionType(connectionName)215 if err != nil {216 return nil, err217 }218 connectionDetails.Type = vType219 // Parse the connection based on the type.220 switch vType { // switch on the connection type...221 case c.ConnectionTypeOracle: // if the user wants Oracle connection details...222 _, err := shared.OracleDsnToOracleConnectionDetails(vDsn)223 if err != nil { // if the DSN was invalid...224 return nil, err225 }226 // Richard Lloyd 20201109 - comment old use of Oracle-specific struct:227 // connectionDetails.Data = shared.OracleConnectionDetailsToMap(connectionDetails.Data, cn)228 connectionDetails.Data = shared.DsnConnectionDetailsToMap(connectionDetails.Data, &shared.DsnConnectionDetails{Dsn: vDsn})229 case c.ConnectionTypeSnowflake: // if the user wants Snowflake connection details...230 _, err := rdbms.SnowflakeParseDSN(vDsn)231 if err != nil { // if the DSN was invalid...232 return nil, err233 }234 connectionDetails.Data = shared.DsnConnectionDetailsToMap(connectionDetails.Data, &shared.DsnConnectionDetails{Dsn: vDsn})235 case c.ConnectionTypeS3: // if the user wants S3 bucket details...236 // Fetch bucket region from the environment.237 var vRegion string238 kRegion := helper.GetRegionEnvVarName(connectionName)239 if err := helper.ReadValueFromEnv(kRegion, &vRegion); err != nil { // if we cannot find the bucket region in the environment...240 // TODO: log this correctly instead of fmt.241 fmt.Printf("bucket region not found in environment variable %v\n", kRegion)242 }243 cn, err := s3.ParseDSN(vDsn, vRegion)244 if err != nil { // if the DSN was invalid...245 return nil, err246 }247 connectionDetails.Data = s3.AwsBucketToMap(connectionDetails.Data, cn)248 default: // fallback to the DSN connection type.249 if actions.IsSupportedConnectionType(vType) { // if the original scheme is supported...250 _, err := dburl.Parse(vDsn)251 if err != nil { // if the DSN was invalid...252 return nil, err253 }254 // Save the connection data.255 connectionDetails.Data = shared.DsnConnectionDetailsToMap(connectionDetails.Data, &shared.DsnConnectionDetails{Dsn: vDsn})256 } else {257 return nil, fmt.Errorf("unsupported connection type %q for DSN %q", vType, vDsn)258 }259 }260 return &connectionDetails, nil261}262// Load connection DSN from the environment, parse it based on type set in the environment263// and return the shared.ConnectionDetails.264// This mimics functionality whereby connection details are loaded from JSON config file, but reads info from265// the environment instead.266// This is used by the pipe action since the full connection details may not be saved out to the pipe config file.267// TODO: add test for LoadConnection268func (t *TwelveFactorConnections) LoadConnection(connectionName string) (shared.ConnectionDetails, error) {269 kDsn := helper.GetDsnEnvVarName(connectionName)270 var vDsn, vType string271 if err := helper.ReadValueFromEnv(kDsn, &vDsn); err != nil { // if we cannot find the DSN in the environment...272 return shared.ConnectionDetails{}, err273 }274 if err := helper.ReadValueFromEnv(envVarSourceType, &vType); err != nil { // if we can't read the source type from the environment...275 return shared.ConnectionDetails{}, err276 }277 vType = strings.TrimSpace(strings.ToUpper(vType)) // sanitise vType.278 m := make(map[string]string) // map for generic connection data.279 switch vType {280 case "ORACLE":281 cn, err := shared.OracleDsnToOracleConnectionDetails(vDsn)282 if err != nil {...

Full Screen

Full Screen

12factor_test.go

Source:12factor_test.go Github

copy

Full Screen

...7 "github.com/relloyd/halfpipe/actions"8 "github.com/relloyd/halfpipe/config"9 "github.com/relloyd/halfpipe/logger"10)11var mockTwelveFactorActions = map[string]twelveFactorAction{12 "cp-snap": {13 setupFunc: func(src string, tgt string) {14 cpSnapCfg.SrcAndTgtConnections.SourceString.ConnectionObject = src15 cpSnapCfg.SrcAndTgtConnections.TargetString.ConnectionObject = tgt16 },17 runnerFunc: getMock12FactorExecutor("cp-snap"),18 },19}20var results = map[string]int{21 "cp-snap": 0,22 "cp-delta": 0,23}24func getMock12FactorExecutor(action string) func() error {25 return func() error {26 results[action] = 127 return nil28 }29}30func TestSetupTwelveFactorMode(t *testing.T) {31 if twelveFactorMode {32 t.Fatal("expected twelveFactorMode to be false; got true")33 }34 _ = os.Setenv(envVarTwelveFactorMode, "1")35 setupTwelveFactorMode()36 if !twelveFactorMode {37 t.Fatal("expected twelveFactorMode to be true; got false")38 }39}40func TestExecute12FactorMode(t *testing.T) {41 log := logger.NewLogger("halfpipe", "error", true)42 var expected, got string43 srcObject := "richard.test_a"44 tgtObject := "richard.test_b"45 var osVars = map[string]string{46 "HP_LOG_LEVEL": "error",47 "HP_SOURCE_DSN": "richard/richard@//192.168.56.101/orcl",48 "HP_TARGET_DSN": "richard/richard@//192.168.56.101/orcl",49 "HP_SOURCE_TYPE": "oracle",50 "HP_TARGET_TYPE": "oracle",51 "HP_SOURCE_OBJECT": srcObject,52 "HP_TARGET_OBJECT": tgtObject,53 "HP_SOURCE_S3_REGION": "xx",54 "HP_TARGET_S3_REGION": "xx",55 "HP_AUTH_KEY": "123xyz456",56 "HP_STACK_DUMP": "1",57 }58 // Setup environment.59 _ = os.Setenv(envVarTwelveFactorMode, "1")60 for k, v := range osVars {61 _ = os.Setenv(k, v)62 }63 // Test 1 - action runner function is called64 log.Info("test 1 - cp snap")65 _ = os.Setenv("HP_COMMAND", "cp")66 _ = os.Setenv("HP_SUBCOMMAND", "snap")67 if err := execute12FactorMode(mockTwelveFactorActions); err != nil {68 t.Fatalf("test 1 failed: expected nil error got error: %v", err)69 }70 assert12FactorExecution(t, "test 1", "cp-snap")71 // Test 2 - invalid command + subcommand72 log.Info("test 2 - invalid command subcommand")73 _ = os.Setenv("HP_COMMAND", "invalidCommand")74 _ = os.Setenv("HP_SUBCOMMAND", "invalidSubcommand")75 if err := execute12FactorMode(mockTwelveFactorActions); err == nil {76 t.Fatal("test 2 failed, expected: error; got: nil")77 }78 // Test 3 - connection objects are set correctly79 log.Info("test 3 - src and tgt connection strings are set correctly")80 _ = os.Setenv("HP_COMMAND", "cp")81 _ = os.Setenv("HP_SUBCOMMAND", "snap")82 if err := execute12FactorMode(mockTwelveFactorActions); err != nil {83 t.Fatalf("test 3 failed: expected nil error got error: %v", err)84 }85 got = cpSnapCfg.SrcAndTgtConnections.SourceString.ConnectionObject86 expected = fmt.Sprintf("%v.%v", defaultConnectionNameSource, srcObject)87 if got != expected {88 t.Fatalf("test 3 failed for source, expected: %v; got: %v", expected, got)89 }90 got = cpSnapCfg.SrcAndTgtConnections.TargetString.ConnectionObject91 expected = fmt.Sprintf("%v.%v", defaultConnectionNameTarget, tgtObject)92 if got != expected {93 t.Fatalf("test 3 failed for target, expected: %v; got: %v", expected, got)94 }95 // Test 4 - all twelveFactorVars are fetched from the environment96 for k := range osVars { // for each hardcoded env var in this test...97 got = twelveFactorVars[k] // check that twelveFactorMode has picked it up!98 expected = osVars[k]99 if got != expected {100 t.Fatalf("expected %v = %v; got: %v", k, expected, got)101 }102 }103 // Test 5 - sensitive vars are set up.104 if _, sensitive := twelveFactorVarsSensitive[envVarAuthKey]; !sensitive {105 t.Fatal("expected envVarAuthKey to be registered in map twelveFactorVarsSensitive")106 }107 // Test 6 - GetConnectionType uses default values.108 ts := TwelveFactorConnections{}109 got, err := ts.GetConnectionType("junk")110 if err == nil {111 t.Fatal("Test 6 junk failed: expected an error, got nil")112 }113 got, err = ts.GetConnectionType(defaultConnectionNameSource)114 expected = twelveFactorVars[envVarSourceType]115 if got != expected {116 t.Fatalf("Test 6 source failed: got %v, expected: %v", got, expected)117 }118 if err != nil {119 t.Fatal("Test 6 source failed: got error: ", err)120 }121 got, err = ts.GetConnectionType(defaultConnectionNameTarget)122 expected = twelveFactorVars[envVarTargetType]123 if got != expected {124 t.Fatalf("Test 6 target failed: got %v, expected: %v", got, expected)125 }126 if err != nil {127 t.Fatal("Test 6 target failed: got error: ", err)128 }129}130func assert12FactorExecution(t *testing.T, testName string, action string) {131 if results[action] == 0 {132 t.Fatalf("%v failed, expected: >0; got: 0", testName)133 }134}135func TestTwelveFactorActions(t *testing.T) {136 // Test that struct twelveFactorActions provides valid actions also handled by CLI Cobra commands.137 // There is an exclude list since some are explicitly invalid.138 // For each key-key in map actions.ActionFuncs{} assert that it exists as a key in map twelveFactorActions{}.139 excludes := map[string]string{140 "cp-meta": "",141 }142 for k1, v1 := range actions.ActionFuncs { // foe each Cobra command action (cp, sync, etc)...143 for k2 := range v1 { // for each subcommand...144 key := fmt.Sprintf("%v-%v", k1, k2) // construct the key145 _, excluded := excludes[key] // check if excluded146 _, ok12 := twelveFactorActions[key] // check if twelveFactorActions handles the action147 if !excluded && !ok12 { // if the action key is not excluded and it is not handled...148 t.Fatalf("twelveFactoinActions does not handle Cobra action %v", key)149 }150 }151 }152}153func TestGetConnectionHandler(t *testing.T) {154 // Test 1155 twelveFactorMode = true156 c := getConnectionHandler()157 tx := reflect.TypeOf(c)158 if tx != reflect.TypeOf(&TwelveFactorConnections{}) {159 t.Fatalf("TestGetConnectionHandler test 1 failed - expected: *cmd.TwelveFactorConnections; got: %v", tx.String())160 }161 // Test 2162 twelveFactorMode = false163 c = getConnectionHandler()164 tx = reflect.TypeOf(c)165 if tx != reflect.TypeOf(config.Connections) {166 t.Fatalf("TestGetConnectionHandler test 2 failed - expected: config.Connections; got: %v", tx.String())167 }168}169func TestGetConnectionLoader(t *testing.T) {170 // Test 1171 twelveFactorMode = true172 c := getConnectionLoader()173 tx := reflect.TypeOf(c)174 if tx != reflect.TypeOf(&TwelveFactorConnections{}) {175 t.Fatalf("TestGetConnectionLoader test 1 failed - expected: *cmd.TwelveFactorConnections; got: %v", tx.String())176 }177 // Test 2178 twelveFactorMode = false179 c = getConnectionLoader()180 tx = reflect.TypeOf(c)181 if tx != reflect.TypeOf(config.Connections) {182 t.Fatalf("TestGetConnectionLoader test 2 failed - expected: config.Connections; got: %v", tx.String())183 }184}...

Full Screen

Full Screen

createpayment.go

Source:createpayment.go Github

copy

Full Screen

1package main2import (3 "log"4 "github.com/vennd/enulib/enulibgo"5)6var payments = []struct {7 BlockchainId string8 SourceAddress string9 DestinationAddress string10 Asset string11 Issuer string12 Quantity uint6413 Passphrase string14 Comment string15}{16 {"counterparty", "1HdnKzzCKFzNEJbmYoa3RcY4MhKPP3NB7p", "1HpkZBjNFRFagyj6Q2adRSagkfNDERZhg1", "SHIMA", "", 1001, "this is the twelve word pass phrase that is the wallet seed"}, "Sending a counterparty asset",17 {"ripple", "rNx9Ddu8Hgi34GdSKhdHu9fuojH9Cb1gv2", "rpu8gxvRzQ2JLQMN7Goxs6x9zffH3sjQBd", "XRP", "", 1000000, "this is a different twelve word passphrase that is the wallet seed"},18 {"ripple", "rG8bvoqzkNow8ttQkLY52v97qe3YKnx8v2", "rst9JK6ANWuVHMqimwVukUXWzfc532vBg9", "GOLD", "rG8bvoqzkNow8ttQkLY52v97qe3YKnx8v2", 30050000000, "this yet another different twelve word passphrase that is the wallet seed", "Sends 300.5 GOLD issued by rG8bvoqzkNow8ttQkLY52v97qe3YKnx8v2 from rG8bvoqzkNow8ttQkLY52v97qe3YKnx8v2 to rst9JK6ANWuVHMqimwVukUXWzfc532vBg9"},19}20func main() {21 enulibgo.Init()22 for _, payment := range payments {23 log.Printf("Creating payment on blockchain %s from %s to %s of %d %s.%s\n", payment.BlockchainId, payment.SourceAddress, payment.DestinationAddress, payment.Quantity, payment.Issuer, payment.Asset)24 result, err := enulibgo.CreatePayment(payment.BlockchainId, payment.SourceAddress, payment.DestinationAddress, payment.Asset, payment.Issuer, payment.Quantity, payment.Passphrase)25 if err != nil {26 log.Println("Payment creation failed")27 log.Fatal(err.Error())28 }29 log.Printf("Payment creation successful. PaymentId: %s, RequestId: %s\n", result.PaymentId, result.RequestId)30 }31}...

Full Screen

Full Screen

012_config_upgrade.go

Source:012_config_upgrade.go Github

copy

Full Screen

2import (3 "fmt"4 "strings"5)6type ZeroTwelveUpgradeCommand struct {7 Meta8}9func (c *ZeroTwelveUpgradeCommand) Run(args []string) int {10 c.Ui.Output(fmt.Sprintf(`11The 0.12upgrade command is deprecated. You must run this command with Terraform12v0.12 to upgrade your configuration syntax before upgrading to the current13version.`))14 return 015}16func (c *ZeroTwelveUpgradeCommand) Help() string {17 helpText := `18Usage: terraform 0.12upgrade19 The 0.12upgrade command is deprecated. You must run this command with20 Terraform v0.12 to upgrade your configuration syntax before upgrading to21 the current version.22`23 return strings.TrimSpace(helpText)24}25func (c *ZeroTwelveUpgradeCommand) Synopsis() string {26 return "Rewrites pre-0.12 module source code for v0.12"27}...

Full Screen

Full Screen

Twelve

Using AI Code Generation

copy

Full Screen

1import "source"2func main() {3 source.Twelve()4}5import "source"6func main() {7 source.Twelve()8}9import "source"10func main() {11 source.Twelve()12}13import "source"14func main() {15 source.Twelve()16}17import "source"18func main() {19 source.Twelve()20}21import "source"22func main() {23 source.Twelve()24}25import "source"26func main() {27 source.Twelve()28}29import "source"30func main() {31 source.Twelve()32}33import "source"34func main() {35 source.Twelve()36}37import "source"38func main() {39 source.Twelve()40}41import "source"42func main() {43 source.Twelve()44}45import "source"46func main() {47 source.Twelve()48}49import "source"50func main() {51 source.Twelve()52}53import "source"54func main() {55 source.Twelve()56}57import "source"58func main() {59 source.Twelve()60}61import "source"62func main() {63 source.Twelve()64}

Full Screen

Full Screen

Twelve

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(source.Twelve())4}5func Twelve() int {6}7The import path is the directory path of the package relative to the GOPATH workspace directory. The import path is

Full Screen

Full Screen

Twelve

Using AI Code Generation

copy

Full Screen

1import "example.com/user/hello/source"2func main() {3 source.Twelve()4}5import "example.com/user/hello/source"6func main() {7 source.Twelve()8}

Full Screen

Full Screen

Twelve

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Twelve: ", Twelve())4}5import "fmt"6func main() {7 fmt.Println("Twelve: ", Twelve())8}9import "fmt"10func main() {11 fmt.Println("Twelve: ", Twelve())12}13import "fmt"14func main() {15 fmt.Println("Twelve: ", Twelve())16}17import "fmt"18func main() {19 fmt.Println("Twelve: ", Twelve())20}21import "fmt"22func main() {23 fmt.Println("Twelve: ", Twelve())24}25import "fmt"26func main() {27 fmt.Println("Twelve: ", Twelve())28}29import "fmt"30func main() {31 fmt.Println("Twelve: ", Twelve())32}33import "fmt"34func main() {35 fmt.Println("Twelve: ", Twelve())36}37import "fmt"38func main() {39 fmt.Println("Twelve: ", Twelve())40}41import "fmt"42func main() {43 fmt.Println("Twelve: ", Twelve())44}45import "fmt"46func main() {47 fmt.Println("Twelve: ", Twelve())48}49import "fmt"50func main() {51 fmt.Println("Twelve: ", Twelve())52}

Full Screen

Full Screen

Twelve

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Twelve is", source.Twelve())4}5import (6func main() {7 fmt.Println("Twelve is", source.Twelve())8}9import (10func main() {11 fmt.Println("Twelve is", source.Twelve())12}13import (14func main() {15 fmt.Println("Twelve is", source.Twelve())16}17import (18func main() {19 fmt.Println("Twelve is", source.Twelve())20}21import (22func main() {23 fmt.Println("Twelve is", source.Twelve())24}25import (26func main() {27 fmt.Println("Twelve is", source.Twelve())28}29import (30func main() {31 fmt.Println("Twelve is", source.Twelve())32}33import (34func main() {35 fmt.Println("Twelve is", source.Twelve())36}37import (38func main() {39 fmt.Println("Twelve is", source.Twelve())40}41import (42func main() {43 fmt.Println("Twelve is", source.Twelve

Full Screen

Full Screen

Twelve

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "source"3func main() {4 fmt.Println(a.Twelve())5}6type Source struct{}7func (s Source) Twelve() int {8}

Full Screen

Full Screen

Twelve

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(source.Twelve())4}5func Twelve() int {6}

Full Screen

Full Screen

Twelve

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(src.Twelve())4}5func Twelve() int {6}

Full Screen

Full Screen

Twelve

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(src.Twelve())4}5func Twelve() int {6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful