Skip to content

Commit e9c387f

Browse files
committed
Increase coverage
Signed-off-by: Pavol Loffay <[email protected]>
1 parent ac885f6 commit e9c387f

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

cmd/builder/internal/builder/main_test.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,121 @@ func getWorkspaceDir() string {
500500
_, thisFile, _, _ := runtime.Caller(0)
501501
return filepath.Dir(filepath.Dir(filepath.Dir(filepath.Dir(filepath.Dir(thisFile)))))
502502
}
503+
504+
func TestGenerateSchemas(t *testing.T) {
505+
tests := []struct {
506+
name string
507+
cfgBuilder func(t *testing.T) *Config
508+
wantErr bool
509+
}{
510+
{
511+
name: "handles empty components",
512+
cfgBuilder: func(t *testing.T) *Config {
513+
cfg := newTestConfig(t)
514+
cfg.Distribution.OutputPath = t.TempDir()
515+
cfg.GenerateSchema = true
516+
cfg.Exporters = []Module{}
517+
cfg.Receivers = []Module{}
518+
cfg.Processors = []Module{}
519+
cfg.Extensions = []Module{}
520+
cfg.Connectors = []Module{}
521+
return cfg
522+
},
523+
wantErr: false,
524+
},
525+
{
526+
name: "logs warning for invalid extension",
527+
cfgBuilder: func(t *testing.T) *Config {
528+
cfg := newTestConfig(t)
529+
cfg.Distribution.OutputPath = t.TempDir()
530+
cfg.GenerateSchema = true
531+
cfg.Extensions = []Module{{Name: "invalid", Import: "nonexistent/ext"}}
532+
cfg.Receivers = []Module{}
533+
cfg.Processors = []Module{}
534+
cfg.Exporters = []Module{}
535+
cfg.Connectors = []Module{}
536+
return cfg
537+
},
538+
wantErr: false,
539+
},
540+
{
541+
name: "logs warning for invalid receiver",
542+
cfgBuilder: func(t *testing.T) *Config {
543+
cfg := newTestConfig(t)
544+
cfg.Distribution.OutputPath = t.TempDir()
545+
cfg.GenerateSchema = true
546+
cfg.Extensions = []Module{}
547+
cfg.Receivers = []Module{{Name: "invalid", Import: "nonexistent/recv"}}
548+
cfg.Processors = []Module{}
549+
cfg.Exporters = []Module{}
550+
cfg.Connectors = []Module{}
551+
return cfg
552+
},
553+
wantErr: false,
554+
},
555+
{
556+
name: "logs warning for invalid processor",
557+
cfgBuilder: func(t *testing.T) *Config {
558+
cfg := newTestConfig(t)
559+
cfg.Distribution.OutputPath = t.TempDir()
560+
cfg.GenerateSchema = true
561+
cfg.Extensions = []Module{}
562+
cfg.Receivers = []Module{}
563+
cfg.Processors = []Module{{Name: "invalid", Import: "nonexistent/proc"}}
564+
cfg.Exporters = []Module{}
565+
cfg.Connectors = []Module{}
566+
return cfg
567+
},
568+
wantErr: false,
569+
},
570+
{
571+
name: "logs warning for invalid exporter",
572+
cfgBuilder: func(t *testing.T) *Config {
573+
cfg := newTestConfig(t)
574+
cfg.Distribution.OutputPath = t.TempDir()
575+
cfg.GenerateSchema = true
576+
cfg.Extensions = []Module{}
577+
cfg.Receivers = []Module{}
578+
cfg.Processors = []Module{}
579+
cfg.Exporters = []Module{{Name: "invalid", Import: "nonexistent/exp"}}
580+
cfg.Connectors = []Module{}
581+
return cfg
582+
},
583+
wantErr: false,
584+
},
585+
{
586+
name: "logs warning for invalid connector",
587+
cfgBuilder: func(t *testing.T) *Config {
588+
cfg := newTestConfig(t)
589+
cfg.Distribution.OutputPath = t.TempDir()
590+
cfg.GenerateSchema = true
591+
cfg.Extensions = []Module{}
592+
cfg.Receivers = []Module{}
593+
cfg.Processors = []Module{}
594+
cfg.Exporters = []Module{}
595+
cfg.Connectors = []Module{{Name: "invalid", Import: "nonexistent/conn"}}
596+
return cfg
597+
},
598+
wantErr: false,
599+
},
600+
}
601+
602+
for _, tt := range tests {
603+
t.Run(tt.name, func(t *testing.T) {
604+
cfg := tt.cfgBuilder(t)
605+
606+
err := GenerateSchemas(cfg)
607+
608+
if tt.wantErr {
609+
require.Error(t, err)
610+
} else {
611+
require.NoError(t, err)
612+
}
613+
614+
// Verify schemas directory was created
615+
schemaDir := filepath.Join(cfg.Distribution.OutputPath, "schemas")
616+
_, err = os.Stat(schemaDir)
617+
require.NoError(t, err, "schemas directory should exist")
618+
})
619+
}
620+
}

0 commit comments

Comments
 (0)