github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/command/providers_mirror_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package command
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/mitchellh/cli"
    11  )
    12  
    13  // More thorough tests for providers mirror can be found in the e2etest
    14  func TestProvidersMirror(t *testing.T) {
    15  	// noop example
    16  	t.Run("noop", func(t *testing.T) {
    17  		c := &ProvidersMirrorCommand{}
    18  		code := c.Run([]string{"."})
    19  		if code != 0 {
    20  			t.Fatalf("wrong exit code. expected 0, got %d", code)
    21  		}
    22  	})
    23  
    24  	t.Run("missing arg error", func(t *testing.T) {
    25  		ui := new(cli.MockUi)
    26  		c := &ProvidersMirrorCommand{
    27  			Meta: Meta{Ui: ui},
    28  		}
    29  		code := c.Run([]string{})
    30  		if code != 1 {
    31  			t.Fatalf("wrong exit code. expected 1, got %d", code)
    32  		}
    33  
    34  		got := ui.ErrorWriter.String()
    35  		if !strings.Contains(got, "Error: No output directory specified") {
    36  			t.Fatalf("missing directory error from output, got:\n%s\n", got)
    37  		}
    38  	})
    39  }