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

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package jsonchecks
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/terramate-io/tf/checks"
    10  )
    11  
    12  type checkStatus []byte
    13  
    14  func checkStatusForJSON(s checks.Status) checkStatus {
    15  	if ret, ok := checkStatuses[s]; ok {
    16  		return ret
    17  	}
    18  	panic(fmt.Sprintf("unsupported check status %#v", s))
    19  }
    20  
    21  func (s checkStatus) MarshalJSON() ([]byte, error) {
    22  	return []byte(s), nil
    23  }
    24  
    25  var checkStatuses = map[checks.Status]checkStatus{
    26  	checks.StatusPass:    checkStatus(`"pass"`),
    27  	checks.StatusFail:    checkStatus(`"fail"`),
    28  	checks.StatusError:   checkStatus(`"error"`),
    29  	checks.StatusUnknown: checkStatus(`"unknown"`),
    30  }