How to get Diff through unit test

Hello,

I am using cdktf in ts. i have written unit test using this. These unit test checks if terraform valid and terraform plan for mentioned stack will work or not but i want to get diff of infra as output of unit tests. how can i get that ? i am using s3Backend to store state files.

import "cdktf/lib/testing/adapters/jest"; // Load types for expect matchers
import { Testing, TerraformStack } from "cdktf";
import { Infrastructure } from "../main"
describe("My CDKTF Application", () => {

  it.todo("should be tested");
  describe("Checking validity", () => {
    it("check if the produced terraform configuration is valid", () => {
      const app = Testing.app();
      const stack = new TerraformStack(app, "test");
      new Infrastructure(stack, 'test-infra');
      expect(Testing.fullSynth(stack)).toBeValidTerraform();
    });

    it("check if this can be planned", () => {
      const app = Testing.app();
      const stack = new TerraformStack(app, "test");
      new Infrastructure(stack, 'test-infra');
      expect(Testing.fullSynth(stack)).toPlanSuccessfully();
    });
  });
});

It isn’t directly supported at this time.
You can call terraform plan yourself and parse the output as a workaround.

Can we mock S3Backend to get the copy of state file on local to test terraform plan without interacting s3 ?

Terraform needs to access the stored state in order to execute a plan. I don’t believe there is any way around that.