wing icon indicating copy to clipboard operation
wing copied to clipboard

creating an rfc for testing

Open tsuf239 opened this issue 2 years ago • 1 comments

Use Case

following 25/01/24 team time - we can only make wing's testing framework great if someone owns it, I'll collect the relevant issues and try my best to create a solid rfc out of them 💪

Proposed Solution

No response

Implementation Notes

No response

Component

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Slack.

tsuf239 avatar Jan 25 '24 16:01 tsuf239

Here are my two cents:

  • test is for preflight code blocks, this keyword is only available in *.test.w files and it creates an isolated environment that can run checks
  • check (or maybe monitor) is for inflight code, nested inside a test block or inside any *.main.w file

test runs in isolation (a test doesn't interfere another test) while check run on the same INFA, and there is no guarantee on order and parallelism .

// *.main.w
bring cloud;
bring util;
bring expect;

let b = new cloud.Bucket();

check "bucket put and get" {
  // check doesn't run in isolation, so a unique file is required
  let file = util.uuidv4(); 
  b.put(file, "1234");
  expect.equal(b.get(file), "1234");
}

check "list bucket" {
  let file = util.uuidv4(); 
  b.put(file, "1234");
  let files = b.list(); // will return a list of more then this file
  assert(files.contains(file));
}

check "this is a bad test" {
  // this check will fail in some cases, depending which check will run first
  expect.equal(b.list().length, 0);
}
// *.test.w
bring cloud;
bring util;
bring expect;

test "empty bucket" {
  let b = new cloud.Bucket();
  
  check "list is empty" {
    expect.equal(b.list().length, 0);
  }
} 

test "bucket addObject" {
  let b = new cloud.Bucket();
  let file = "file";
  b.addObject(file ,"xyz");
  check "list return 1" {
    expect.equal(b.list().length, 1);
    expect.equal(b.list().at(0), file);
  }
  check "add object returns right content" {
    expect.equal(b.get(file), "xyz");
  }
} 

ekeren avatar Jan 25 '24 17:01 ekeren